{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f21925d1-86ce-477c-a69c-e48d6835972b",
   "metadata": {},
   "source": [
    "## Marker Rotation\n",
    "\n",
    "Specify marker rotation (in degrees) using the `angle` aesthetic."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7f7b5b9d-9ae5-4518-8a0f-55d00deb040f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"FRbKME\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"library\">\n",
       "       if(!window.letsPlotCallQueue) {\n",
       "           window.letsPlotCallQueue = [];\n",
       "       }; \n",
       "       window.letsPlotCall = function(f) {\n",
       "           window.letsPlotCallQueue.push(f);\n",
       "       };\n",
       "       (function() {\n",
       "           var script = document.createElement(\"script\");\n",
       "           script.type = \"text/javascript\";\n",
       "           script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v4.3.3/js-package/distr/lets-plot.min.js\";\n",
       "           script.onload = function() {\n",
       "               window.letsPlotCall = function(f) {f();};\n",
       "               window.letsPlotCallQueue.forEach(function(f) {f();});\n",
       "               window.letsPlotCallQueue = [];\n",
       "               \n",
       "               \n",
       "           };\n",
       "           script.onerror = function(event) {\n",
       "               window.letsPlotCall = function(f) {};\n",
       "               window.letsPlotCallQueue = [];\n",
       "               var div = document.createElement(\"div\");\n",
       "               div.style.color = 'darkred';\n",
       "               div.textContent = 'Error loading Lets-Plot JS';\n",
       "               document.getElementById(\"FRbKME\").appendChild(div);\n",
       "           };\n",
       "           var e = document.getElementById(\"FRbKME\");\n",
       "           e.appendChild(script);\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%useLatestDescriptors\n",
    "%use lets-plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1a27a1e0-a76e-4c29-9506-aadf5ec766f0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Lets-Plot Kotlin API v.4.7.3-SNAPSHOT. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.3.3."
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "LetsPlot.getInfo()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "233d263e-ea61-4220-b4a7-1d7dfe24bff6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"ituaJ0\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "\"a\":[0.0,90.0,180.0,270.0],\n",
       "\"x\":[1.0,2.0,3.0,4.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"angle\":\"a\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"shape\":14.0,\n",
       "\"size\":10.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"ituaJ0\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val data = mapOf(\n",
    "    \"x\" to listOf(1, 2, 3, 4),\n",
    "    \"a\" to listOf(0, 90, 180, 270),\n",
    "    \"c\" to listOf(\"a\", \"b\", \"c\", \"o\")\n",
    ")\n",
    "letsPlot(data) + geomPoint(shape = 14, size = 10) { x = \"x\"; angle = \"a\" }"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a5b47a33-9d9c-4bb3-8d2a-c69d3e114a96",
   "metadata": {},
   "source": [
    "#### Boxplot outlier rotation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a908637c-e1c9-4a70-9188-801550f9ec95",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"wZIYn5\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"stat\":\"boxplot\",\n",
       "\"shape\":14.0,\n",
       "\"position\":\"dodge\",\n",
       "\"geom\":\"boxplot\",\n",
       "\"data\":{\n",
       "\"..middle..\":[0.5032039775838979,0.4994956383420928],\n",
       "\"..upper..\":[0.7489937957331902,0.7538483427592402],\n",
       "\"..ymax..\":[0.9998705265855844,0.9998599212205099],\n",
       "\"x\":[\"A\",\"B\"],\n",
       "\"..lower..\":[0.252726874226669,0.24472940448782615],\n",
       "\"..ymin..\":[1.6683206914502868E-5,2.3481177499740102E-4]\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"stat\":\"boxplot_outlier\",\n",
       "\"shape\":14.0,\n",
       "\"size\":8.0,\n",
       "\"angle\":90.0,\n",
       "\"show_legend\":false,\n",
       "\"position\":\"dodge\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "\"..middle..\":[0.5032039775838979,0.4994956383420928],\n",
       "\"..upper..\":[0.7489937957331902,0.7538483427592402],\n",
       "\"..ymax..\":[0.9998705265855844,0.9998599212205099],\n",
       "\"x\":[\"A\",\"B\"],\n",
       "\"..lower..\":[0.252726874226669,0.24472940448782615],\n",
       "\"y\":[1.5,1.55],\n",
       "\"..ymin..\":[1.6683206914502868E-5,2.3481177499740102E-4]\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"wZIYn5\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import kotlin.random.Random\n",
    "\n",
    "fun getRandomList(n: Int, random: Random): MutableList<Double> =\n",
    "    MutableList(n) { random.nextDouble() }\n",
    "    \n",
    "val rnd = Random(42)\n",
    "val n = 10000\n",
    "val yA = getRandomList(n, rnd)\n",
    "val yB = getRandomList(n, rnd)\n",
    "\n",
    "// add outlier\n",
    "yA[yA.lastIndex] = 1.5\n",
    "yB[yB.lastIndex] = 1.55\n",
    "\n",
    "val randomBoxData = mapOf(\n",
    "    \"x\" to (List(n) { \"A\" } + List(n) { \"B\" }),\n",
    "    \"y\" to (yA + yB),\n",
    ")\n",
    "\n",
    "letsPlot(randomBoxData) + geomBoxplot(shape=14, outlierSize=2, outlierAngle=90) { \n",
    "    x = \"x\"\n",
    "    y = \"y\"\n",
    "}"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Kotlin",
   "language": "kotlin",
   "name": "kotlin"
  },
  "language_info": {
   "codemirror_mode": "text/x-kotlin",
   "file_extension": ".kt",
   "mimetype": "text/x-kotlin",
   "name": "kotlin",
   "nbconvert_exporter": "",
   "pygments_lexer": "kotlin",
   "version": "1.9.23"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
